﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Markup;
using System.Reflection;

using QUT.Bio.Util;

namespace DBLoader {
	/// <summary>
	/// Interaction logic for HelpWindow.xaml
	/// </summary>
	public partial class HelpWindow : Window {
		public HelpWindow () {
			InitializeComponent();
			
			Type type = GetType();
			Type fdrType = typeof( FlowDocumentReader );
			BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;

			foreach ( FieldInfo fieldInfo in type.GetFields( bindingFlags ) ) {
				if ( fdrType.IsAssignableFrom( fieldInfo.FieldType ) ) {
					try {
						using ( FileStream xamlFile = new FileStream( 
							"Help\\" + fieldInfo.Name + ".xaml", 
							FileMode.Open, 
							FileAccess.Read 
						) ) {
							FlowDocument content = XamlReader.Load( xamlFile ) as FlowDocument;
							FlowDocumentReader docReader = (FlowDocumentReader) fieldInfo.GetValue( this );
							docReader.Document = content;
						}
					}
					catch ( Exception e ) {
						Alert.Show( "Error reading help document {0}:\n\t{1}", fieldInfo.Name, e.Message );
					}
				}
			}
		}
	}
}
